//
//  SAPermissionsCell2.m
//  Saas
//
//  Created by 黄志刚 on 2021/1/19.
//  Copyright © 2021 bing. All rights reserved.
//

#import "SAPermissionsCell2.h"
#import "SAPermissionsModel.h"

@interface SAPermissionsCell2 ()

@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIButton *templateBtn;
@property (nonatomic, strong) UIButton *templateBtn2;
@property (nonatomic, strong) UIButton *templateBtn3;

@end

@implementation SAPermissionsCell2

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAPermsListModel *)model {
    _model = model;
    _templateBtn.hidden = (model.perms1.noShow == YES);
    _templateBtn2.hidden = (model.perms2.noShow == YES);
    _templateBtn3.hidden = (model.perms3.noShow == YES);
    
    _templateBtn.selected = [model.perms1.isDelete isEqualToString:@"0"];
    _templateBtn2.selected = [model.perms2.isDelete isEqualToString:@"0"];
    _templateBtn3.selected = [model.perms3.isDelete isEqualToString:@"0"];
    
    [_templateBtn setTitle:[NSString stringWithFormat:@" %@",model.perms1.menuName] forState:UIControlStateNormal];
    [_templateBtn2 setTitle:[NSString stringWithFormat:@" %@",model.perms2.menuName] forState:UIControlStateNormal];
    [_templateBtn3 setTitle:[NSString stringWithFormat:@" %@",model.perms3.menuName] forState:UIControlStateNormal];
}

#pragma mark - event
-(void)clickedTemplateBtn:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    if (sender.selected == YES) {
        self.model.perms1.isDelete = @"0";
    }else {
        self.model.perms1.isDelete = @"1";
    }
    !self.updateStatusBlock ?: self.updateStatusBlock();
}

-(void)clickedTemplateBtn2:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    if (sender.selected == YES) {
        self.model.perms2.isDelete = @"0";
    }else {
        self.model.perms2.isDelete = @"1";
    }
    !self.updateStatusBlock ?: self.updateStatusBlock();
}

-(void)clickedTemplateBtn3:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    if (sender.selected == YES) {
        self.model.perms3.isDelete = @"0";
    }else {
        self.model.perms3.isDelete = @"1";
    }
    !self.updateStatusBlock ?: self.updateStatusBlock();
}

#pragma mark - initUI
-(void)initUI {
    [self.contentView addSubview:self.templateBtn];
    [self.contentView addSubview:self.templateBtn2];
    [self.contentView addSubview:self.templateBtn3];
    [self.contentView addSubview:self.line];
}

-(UIButton *)templateBtn {
    if (!_templateBtn) {
        _templateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _templateBtn.frame = CGRectMake(kScaleNum(20), 0, kScaleNum(150), kScaleNum(45));
        [_templateBtn setImage:[UIImage imageNamed:@"StaffManager_rect"] forState:UIControlStateNormal];
        [_templateBtn setImage:[UIImage imageNamed:@"StaffManager_rect2"] forState:UIControlStateSelected];
        _templateBtn.titleLabel.font = kFont(14);
        [_templateBtn setTitleColor:kGrayColor forState:UIControlStateNormal];
        _templateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_templateBtn addTarget:self action:@selector(clickedTemplateBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _templateBtn;
}

-(UIButton *)templateBtn2 {
    if (!_templateBtn2) {
        _templateBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        _templateBtn2.frame = CGRectMake(kScaleNum(132), 0, kScaleNum(150), kScaleNum(45));
        [_templateBtn2 setImage:[UIImage imageNamed:@"StaffManager_rect"] forState:UIControlStateNormal];
        [_templateBtn2 setImage:[UIImage imageNamed:@"StaffManager_rect2"] forState:UIControlStateSelected];
        _templateBtn2.titleLabel.font = kFont(14);
        [_templateBtn2 setTitleColor:kGrayColor forState:UIControlStateNormal];
        _templateBtn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_templateBtn2 addTarget:self action:@selector(clickedTemplateBtn2:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _templateBtn2;
}

-(UIButton *)templateBtn3 {
    if (!_templateBtn3) {
        _templateBtn3 = [UIButton buttonWithType:UIButtonTypeCustom];
        _templateBtn3.frame = CGRectMake(kScaleNum(243), 0, kScaleNum(130), kScaleNum(45));
        [_templateBtn3 setImage:[UIImage imageNamed:@"StaffManager_rect"] forState:UIControlStateNormal];
        [_templateBtn3 setImage:[UIImage imageNamed:@"StaffManager_rect2"] forState:UIControlStateSelected];
        _templateBtn3.titleLabel.font = kFont(14);
        [_templateBtn3 setTitleColor:kGrayColor forState:UIControlStateNormal];
        _templateBtn3.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_templateBtn3 addTarget:self action:@selector(clickedTemplateBtn3:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _templateBtn3;
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(44), kScreenWidth, kScaleNum(1))];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}


@end
